package com.ruoyi.milktea.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.milktea.domain.SysUsere;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.milktea.domain.TeaShop;
import com.ruoyi.milktea.service.ITeaShopService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商店管理Controller
 * 
 * @author ruoyi
 * @date 2021-11-26
 */
@RestController
@RequestMapping("/milktea/shop")
public class TeaShopController extends BaseController
{
    @Autowired
    private ITeaShopService teaShopService;

    /**
     * 用户 选择
     */
    @GetMapping("/sysUser")
    public List<SysUsere> sysUser(){
        List<SysUsere> list = teaShopService.selectSysUser();
        return list;
    }

    /**
     * 查询商店管理列表
     */
//    @PreAuthorize("@ss.hasPermi('milktea:shop:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeaShop teaShop)
    {
        startPage();
        List<TeaShop> list = teaShopService.selectTeaShopList(teaShop);
        return getDataTable(list);
    }

    /**
     * 导出商店管理列表
     */
    @PreAuthorize("@ss.hasPermi('milktea:shop:export')")
    @Log(title = "商店管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeaShop teaShop)
    {
        List<TeaShop> list = teaShopService.selectTeaShopList(teaShop);
        ExcelUtil<TeaShop> util = new ExcelUtil<TeaShop>(TeaShop.class);
        util.exportExcel(response, list, "商店管理数据");
    }

    /**
     * 获取商店管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('milktea:shop:query')")
    @GetMapping(value = "/{shopId}")
    public AjaxResult getInfo(@PathVariable("shopId") Long shopId)
    {
        return AjaxResult.success(teaShopService.selectTeaShopByShopId(shopId));
    }

    /**
     * 新增商店管理
     */
    @PreAuthorize("@ss.hasPermi('milktea:shop:add')")
    @Log(title = "商店管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeaShop teaShop)
    {
        return toAjax(teaShopService.insertTeaShop(teaShop));
    }

    /**
     * 修改商店管理
     */
    @PreAuthorize("@ss.hasPermi('milktea:shop:edit')")
    @Log(title = "商店管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeaShop teaShop)
    {
        System.out.println("teaShop:"+teaShop);
        return toAjax(teaShopService.updateTeaShop(teaShop));
    }

    /**
     * 删除商店管理
     */
    @PreAuthorize("@ss.hasPermi('milktea:shop:remove')")
    @Log(title = "商店管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shopIds}")
    public AjaxResult remove(@PathVariable Long[] shopIds)
    {
        return toAjax(teaShopService.deleteTeaShopByShopIds(shopIds));
    }
}
